<%@ page language="java" import="java.util.List, com.cartview.bean.CartView, com.opensymphony.xwork2.ActionContext"
 contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width">
<link href="css/shoppingcar.css" rel="stylesheet">
<title>查看购物车</title>

<script language="javascript">
 function sub(num){
 if(document.getElementById(num).value>1)
     document.getElementById(num).value-=1;
 }
       function add(num){
     document.getElementById(num).value=document.getElementById(num).value-1+2;
 }
 </script>
</head>
<%
	List<CartView> view = (List<CartView>) (ActionContext.getContext().getSession().get("cartview"));
	String username = (String) ActionContext.getContext().getSession().get("user");
%>
<body>
	<div id="userbar">
		<table>
			<tr height="30px">
				<td align="left" width="40px"><img src="images/user.png"
					width="30px" height="30px" alt="" /></td>
				<td width="500px">你好，<%= username%>!</td>
				<td width="120px" align="left"><a href="index.jsp"
					style="text-decoration: none"><font size=3 color="black">书店首页</font></a></td>
				<td width="120px" align="left"><a href="#"
					style="text-decoration: none"><font size=3 color="black">购物车</font></a></td>
				<td width="80px" align="rignt"><a href=""
					style="text-decoration: none"><font size=3 color="black">联系我们</font></a></td>
			</tr>
		</table>
	</div>
	<div id="header">
		<img src="images/shopping-login.jpg" width="927" height="110" alt="" />
	</div>
	<div id="container">
		<form>
			<table align="center" width="907px" border="0" cellSpacing="0"
				cellpadding="0">
				<tr bgcolor="#C8C8C8" height="40px">
					<td width="220px"><input type="checkbox" name="checkbox1"
						value="checkbox" class="out-left"> 全选</td>
					<td width="300px" align="left">商品名称</td>
					<td width="110px" align="center">单价</td>
					<td width="100px" align="center">数量</td>
					<td width="110px" align="center">小计</td>
					<td align="center">操作</td>
				</tr>
			</table>
			<table align="center" width="907px" border="0" cellSpacing="0" cellpadding="0px">
				<%
					double sum = 0;
					if (view != null) {
						for (int i = 0; i < view.size(); ++i) {
							CartView currentView = view.get(i);
							String bookname = currentView.getBook_name();
							double price = currentView.getBook_price();
							int amount = currentView.getAmount();
							double temp = price * amount;
							sum += temp;
							String book_id = currentView.getBook_id();
							String imagePath = "images/" + book_id + ".jpg";
				%>
				<tr bgcolor="white" height="80px">
					<td width="70px" align="left"><input type="checkbox"
						name="checkbox1" value="checkbox" class="left"><a href="#"><img
							src="<%= imagePath%>" width="42px" height="60px" class="center" /></a></td>
					<td width="300px" align="left">${bookname}</td>
					<td width="70px" align="center">¥<%= price%></td>
					<td width="80px" align="center"><input type="button"
						name="Submit" onclick="sub(<%= i + 1%>)" value="-"
						style="width: 23px; height: 23px; cursor: pointer; background: white;" /><input
						id="<%= i + 1%>" type="text" name="amount"
						style="width: 50px; height: 20px; text-align: center;" value="<%= amount%>"
						onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
						onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
						onblur="if(this.value==''){this.value='<%= amount%>'}" /><input type="button"
						name="Submit" onclick="add(<%= i + 1%>)" value="+"
						style="width: 23px; height: 23px; cursor: pointer; background: white;" /></td>
					<td width="75px" align="center"><font color="#F00">¥<%= temp%></font></td>
					<td width="45px" align="center"><a href="deleteOneAction?bookid=<%= book_id%>"
						style="text-decoration: none">删除</a></td>
				</tr>
				<tr height="2px"></tr>
				<%
					}
				}
			%>
			</table>
			<table align="center" width="907px" cellSpacing="0">
				<tr height="4px">
				<tr>
				<tr bgcolor="#F0F0F0" height="30px">
					<td width="70px" class="leftbox"><input type="checkbox"
						name="checkbox1" value="checkbox"> 全选</td>
					<td width="70px" class="leftbox"><a href="#"
						style="text-decoration: none">批量删除</a></td>
					<td width="227px" align="right" class="rightbox"><%= view.size()%>件商品金额总计：¥<%= sum%>
					</td>
				</tr>
				<tr bgcolor="#F0F0F0" height="120px">
					<td width="70px" class="leftbox"></td>
					<td width="70px" class="leftbox"></td>
					<td width="227px" align="right" class="rightbox2">应付总额（不含运费）：<font
						color="#F00">¥<%= sum%></font> <a href="#"><img
							src="images/jiesuan.jpg" width="190px" height="40px"
							class="bottombox"></a></td>
				</tr>
				<tr height="4px">
				<tr>
			</table>
		</form>
	</div>
</body>
</html>
